home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / egs-tools / egs_dev-disk / egsdemos / moreexamples / example3 / example3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-06  |  3.5 KB  |  103 lines

  1.                            /*  Example 3.c
  2.                                This code follows the overview of gadgets doc
  3.                                included with this developer disk.
  4.  
  5.                                Patrick Hager, Great Valley Products Inc.
  6.                                October 30, 1993
  7.                            */
  8. #include <stdio.h>
  9. #include "/global/userwindow.h"
  10. #include "/global/egslibraries.h"
  11.  
  12. #include <egs/egsintui.h>
  13. #include <egs/clib/egsintui_protos.h>
  14. #include <egs/pragmas/egsintui_pragmas.h>
  15. #include <egs/egsgadbox.h>
  16. #include <egs/clib/egsgadbox_protos.h>
  17. #include <egs/pragmas/egsgadbox_pragmas.h>
  18.  
  19.  
  20. #define TESTING_ID 200
  21.  
  22.  
  23. struct UserInputWindow Example_Request;
  24.  
  25. EB_GadBoxPtr Create_Example (UserInputWindowPtr UserWindow);
  26. void GadgetDown_Example (UserInputWindowPtr UserWindow, EI_GadgetPtr iaddress);
  27.  
  28. void main (void) {
  29.  
  30.   if (OpenEGSLibraries ()) {
  31.     Init_UserWindow (&Example_Request, "Example Window",WINDOW_MODAL,NULL,
  32.                      NULL);
  33.     Example_Request.Create = Create_Example;
  34.     Example_Request.GadgetDown = GadgetDown_Example;
  35.     Example_Request.IDCMPFlags = EI_iCLOSEWINDOW | EI_iSIZEVERIFY |
  36.                                  EI_iNEWSIZE | EI_iGADGETDOWN;
  37.     Example_Request.Flags =      EI_SIZEBBOTTOM| EI_SIMPLE_REFRESH |
  38.                                  EI_GIMMEZEROZERO;
  39.     Example_Request.SysGadgets = (EI_WINDOWCLOSE)|(EI_WINDOWSIZE)|EI_WINDOWDRAG;
  40.  
  41.     if (Open_UserWindow (&Example_Request,-1,-1)) {
  42.       Close_UserWindow (&Example_Request);
  43.     }
  44.     else
  45.       printf ("Couldn't open my window!\n");
  46.   }
  47.   CloseEGSLibraries ();  // after the bracket cause what if I opened 3 but
  48.                          // couldn't find the rest, still need to close the 3.
  49. }
  50.  
  51. /*************************************
  52.    PRIVATE:  Create_Example.
  53.              This routine is called by the UserWindow routines.
  54.              It passes back a GadBoxPtr to the gadgets wanted.
  55. *************************************/
  56. EB_GadBoxPtr Create_Example (UserInputWindowPtr UserWindow) {
  57.   EB_GadBoxPtr root, verti, horiz;
  58.   EB_GadContext gadcon;
  59.  
  60.   gadcon = UserWindow->GadCon;
  61.  
  62.   root = EB_CreateVertiBox (gadcon);
  63.   EB_AddLastSon (root,EB_CreateVertiFill (gadcon,0,0));
  64.   EB_AddLastSon (root,EB_CreateTextAction (gadcon,"Gadget 1",TESTING_ID,EB_FILL_ALL));
  65.   EB_AddLastSon (root,EB_CreateVertiFill (gadcon,0,0));
  66.     horiz=EB_CreateHorizBox (gadcon);
  67.     EB_AddLastSon (horiz,EB_CreateTextAction (gadcon,"Gadget 2",TESTING_ID+1,EB_FILL_ALL));
  68.     EB_AddLastSon (horiz,EB_CreateTextAction (gadcon,"Gadget 3",TESTING_ID+2,EB_FILL_ALL));
  69.       verti = EB_CreateVertiBox (gadcon);
  70.       EB_AddLastSon (verti,EB_CreateTextAction (gadcon,"Gadget 4",TESTING_ID+3,EB_FILL_ALL));
  71.       EB_AddLastSon (verti,EB_CreateTextAction (gadcon,"Gadget 5",TESTING_ID+4,EB_FILL_ALL));
  72.     EB_AddLastSon (horiz, verti);
  73.   EB_AddLastSon (root,horiz);
  74.  
  75.   return root;
  76. }
  77.  
  78. /**************************************
  79.     PRIVATE:  GadgetDown_Example.
  80.               This routine handles the gadget down events passed to the
  81.               Example Control Window.
  82. **************************************/
  83. void GadgetDown_Example (UserInputWindowPtr UserWindow, EI_GadgetPtr iaddress) {
  84.  
  85.  
  86.   switch (iaddress->GadgetID) {
  87.     case TESTING_ID:
  88.       printf ("You hit Gadget 1!\n");
  89.     break;
  90.     case TESTING_ID+1:
  91.       printf ("You hit Gadget 2!\n");
  92.     break;
  93.     case TESTING_ID+2:
  94.       printf ("You hit Gadget 3!\n");
  95.     break;
  96.     case TESTING_ID+3:
  97.       printf ("You hit Gadget 4!\n");
  98.     break;
  99.     case TESTING_ID+4:
  100.       printf ("You hit Gadget 5!\n");
  101.     break;
  102.   }
  103. }